package com.asl.framework.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

/**
 * @author 482944566@qq.com
 * @version 1.0
 * @date 2025-05-15
 */
@Configuration
public class RestTemplateConfig {
    @Bean
    public RestTemplate restTemplate() {
        RestTemplate restTemplate = new RestTemplate();
        // 设置超时时间（单位：毫秒）
        HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
        factory.setConnectTimeout(5000);  // 连接超时
        factory.setReadTimeout(10000);    // 读取超时
        restTemplate.setRequestFactory(factory);
        return restTemplate;
    }
}
